#define _CRT_SECURE_NO_WARNINGS 1
#include <set>
#include <iostream>
#include <vector>
#include <string>
#include <functional>
using namespace std;
//const int N = 1e5 + 7;
//int ar[N], dp[N], n, s, l;
//multiset<int> st, pt;
//int main() {
//	cin >> n >> s >> l;
//	for (int i = 1; i <= n; ++i)cin >> ar[i];
//	for (int i = 1, j = 1; i <= n; ++i) {
//		st.insert(ar[i]);
//		for (; *st.rbegin() - *st.begin() > s; ++j) {
//			st.erase(st.find(ar[j]));
//			if (i - j >= l)
//				pt.erase(pt.find(dp[j - 1]));
//		}
//		if (i - j + 1 >= l)
//			pt.insert(dp[i - l]);
//		if (pt.begin() == pt.end())dp[i] = N;
//		else dp[i] = *pt.begin() + 1;
//	}
//	int ret = dp[n] >= N ? -1 : dp[n];
//	cout << ret;
//}

int main()
{
	int n;
	int a[1000], b[1000];
	scanf("%d",&n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	for (int i = 0; i < n; i++) scanf("%d", &b[i]);
	vector<int>st;
	for (int i = 0; i < n; i++) {
		while (st.size() && a[st.back()] > a[i])
			st.pop_back();
		st.push_back(i);
	}
	function<int(int)>bound = [&](int k)->int {
		int l = 0, r = st.size() - 1;
		while (l <= r) {
			int mid = l + (r - l) / 2;
			if (a[st[mid]] > k) r = mid - 1;
			else l = mid + 1;
		}
		return l==st.size()?l-1:l;
	};
	int pos1 = bound(b[0]);//>b[0]
	int pos2 = bound(b[0] - 1);//>b[0]-1 <=> >=b[0]
	string s1=to_string(a[st[0]]), s2= to_string(a[st[0]]);
	for (int i = 1; i <= pos1; i++) s1 += " " + to_string(a[st[i]]);
	for (int i = 0; i <= pos1; i++) s1 += " " + to_string(b[st[i]]);
	for (int i = 1; i <= pos2; i++) s2 += " " + to_string(a[st[i]]);
	for (int i = 0; i <= pos2; i++) s2 += " " + to_string(b[st[i]]);
	if (s1 < s2) cout << s1;
	else cout << s2;
	return 0;
}


class Solution {
public:
	int getMoneyAmount(int n) {
		vector<vector<int>>memo(n + 1, vector<int>(n + 1, -1));
		function<int(int, int)>dfs = [&](int l, int r)->int {
			if (l >= r) return 0;
			if (memo[l][r] != -1) return memo[l][r];
			int res = INT_MAX / 2;
			for (int i = l; i <= r; i++) {
				res = min(max(dfs(l, i - 1), dfs(i + 1, r)) + i, res);
			}
			return memo[l][r] = res;
		};
		return dfs(1, n);
	}
};


class Solution {
	int n, m;
	const int dir[4][2] = { 0,1,0,-1,1,0,-1,0 };
public:
	int dfs(vector<vector<int>>& matrix, int x, int y, vector<vector<int>>& memo) {
		if (memo[x][y] != -1)
			return memo[x][y];
		int res = 1;
		for (int i = 0; i < 4; i++) {
			int xi = x + dir[i][0], yi = y + dir[i][1];
			if (xi < 0 || xi >= n || yi < 0 || yi >= m || matrix[xi][yi] <= matrix[x][y])
				continue;
			res = max(dfs(matrix, xi, yi, memo) + 1, res);
		}
		return memo[x][y] = res;
	}
	int longestIncreasingPath(vector<vector<int>>& matrix) {
		n = matrix.size(), m = matrix[0].size();
		auto memo = vector<vector<int>>(n, vector<int>(m, -1));
		int ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (memo[i][j] == -1)
					memo[i][j] = dfs(matrix, i, j, memo);
				ans = max(ans, memo[i][j]);
			}
		}
		return ans;
	}
};